package com.search.controller;

import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

@Slf4j
public class Demo {
    public static void main(String[] args) throws IOException {
        Connection connection = Jsoup.connect("https://book.douban.com/subject/2147090");
        connection.header("sec-fetch-site","none");
        connection.header("upgrade-insecure-requests","1");
        connection.header("cookie","ll=\"108288\"; bid=F9-W7MCOcmY; _pk_id.100001.3ac3=79660cc1e01fac24.1723820565.; douban-fav-remind=1; __utmv=30149280.6649; __yadk_uid=ZHJhWDSJiNZ2MH9YhVnmgxQbFvfyMqfI; _vwo_uuid_v2=D73A86D855AEA200504494DB07D45E995|117418fc07de55be6e666a1331b7531e; _vwo_uuid_v2=D73A86D855AEA200504494DB07D45E995|117418fc07de55be6e666a1331b7531e; _ga_RXNMP372GL=GS1.1.1725441315.5.1.1725442928.60.0.0; _ga=GA1.2.372323296.1723824931; _ga_PRH9EWN86K=GS1.2.1726111153.1.0.1726111153.0.0.0; __utmz=30149280.1726363540.81.24.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); __utmz=81379588.1727533803.59.48.utmcsr=douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/link2/; viewed=\"36609039_31313391_30908519_30783821_30582710_30540166_30726005_30779961_30819205_30521794\"; push_noty_num=0; push_doumail_num=0; dbcl2=\"66490248:EtA/OK6JkwE\"; ct=y; ck=_9nv; frodotk_db=\"d0fd3ce1e82c0f5d72f7b6a5b8842e17\"; _pk_ref.100001.3ac3=%5B%22%22%2C%22%22%2C1735633283%2C%22https%3A%2F%2Fwww.douban.com%2F%22%5D; _pk_ses.100001.3ac3=1; ap_v=0,6.0; __utma=30149280.43806817.1723824835.1734008858.1735638240.94; __utmc=30149280; __utmt_douban=1; __utmb=30149280.1.10.1735638240; __utma=81379588.1255629465.1723824837.1727533803.1735638240.60; __utmc=81379588; __utmt=1; __utmb=81379588.1.10.1735638240");
        connection.header("sec-ch-ua","\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"");
        connection.header("accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
        connection.header("sec-ch-ua-platform","Windows");
        connection.header("sec-fetch-user","?1");
        connection.header("cache-control","max-age=0");
        connection.header("sec-fetch-mode","navigate");
        connection.header("accept-language","zh-CN,zh;q=0.9");
        connection.header("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36");
        connection.header("sec-fetch-dest","document");
        connection.header("priority","u=0, i");
        connection.header("sec-ch-ua-mobile","?0");
        Document doc = null;
        try {
            doc = connection.get();
        } catch (IOException e) {
            log.error("出错"+e.toString());
            e.printStackTrace();
            return;
        }
        Elements newsHeadlines = doc.getElementsByClass("subject-item");

        System.out.println(newsHeadlines.size());

    }
}
